//
//  DoomButton.m
//  MobileDoom
//
//  Created by Steven Troughton-Smith on 26/07/2008.
//  Copyright 2008 Steven Troughton-Smith. All rights reserved.
//

#import "DoomButton.h"
#include "HelperFunctions.h"

BOOL _touching = NO;

@implementation DoomButton

-(void)drawRect:(CGRect)r
{
	[[UIColor whiteColor] set];
	
	fillRoundedRect(UIGraphicsGetCurrentContext(), r, 10, 10);

	if (_touching)
		[[UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0] set];
	else
		[[UIColor blackColor] set];
	
	fillRoundedRect(UIGraphicsGetCurrentContext(), CGRectInset(r, 5, 5), 8, 8);

	
	[super drawRect:r];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	_touching = YES;
	[doomView performSelector:@selector(buttonDown:) withObject:self];
	[self setNeedsDisplay];
}

- (void)touchesCanceled
{
	if (_touching)
	{
		[doomView performSelector:@selector(buttonUp:) withObject:self];
		_touching = NO;
	}
	[self setNeedsDisplay];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	if (_touching)
	{
		[doomView performSelector:@selector(buttonUp:) withObject:self];
		_touching = NO;
	}
	[self setNeedsDisplay];

}

- (void)dealloc {
    [super dealloc];
}


@end
